@extends('layouts.admin')

@section('style')

@endsection

@section('content')
  
 
    <!-- Content Header (Page header) -->
    <section class="content">
    <div class="col-md-9" style="width: 100%">
          <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#activity" data-toggle="tab" aria-expanded="true">基本信息</a></li>
                <li class=""><a href="#timeline" data-toggle="tab" aria-expanded="false">其他信息</a></li>
                <li class=""><a href="#settings" data-toggle="tab" aria-expanded="false">sku</a></li>
                <li class=""><a href="#package" data-toggle="tab" aria-expanded="false">套餐</a></li>
            </ul>
            <form class="form-horizontal" action="{{route('admin.item.store')}}" method="POST" enctype="multipart/form-data">
            <div class="tab-content">
                <div class="tab-pane active" id="activity">
                
                {{ csrf_field() }}
                    <div class="box-body">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">商品唯一货号</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="sncode" id="inputEmail3" placeholder="商品唯一货号" value="{{old('sncode')}}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">商品名字</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="name" id="inputEmail3" placeholder="商品名字" value="{{old('name')}}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">商品库存数量</label>

                            <div class="col-sm-10">
                             <input type="text" class="form-control" name="stock" id="inputEmail3" placeholder="商品库存数量" value="{{old('stock')}}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">下单后锁定的数量</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="locked" id="inputEmail3" placeholder="下单后锁定的数量" value="{{old('locked')}}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">商品的重量</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="weight" id="inputEmail3" placeholder="商品的重量，以千克为单位kg" value="{{old('weight')}}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">市场售价</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="market_price" id="market_price" placeholder="市场售价1.00" value="{{old('market_price')}}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">本店售价</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="price" id="price" placeholder="本店售价1.00" value="{{old('price')}}">
                            </div>
                        </div>

                        
                     
                    </div>
                
                </div>
              <!-- /.tab-pane -->
                <div class="tab-pane" id="timeline">
                
               
                    <div class="box-body">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">seo关键字</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="keywords" id="inputEmail3" placeholder="seo关键字" value="{{old('keywords')}}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">简介</label>

                            <div class="col-sm-10">
                              <input type="text" class="form-control" name="brief" id="inputEmail3" placeholder="商品名字" value="{{old('brief')}}">
                            </div>
                        </div>

                        <div class="form-group">
                                <label for="inputEmail3" class="col-sm-2 control-label">商品详情描述</label>
                                <div class="col-sm-10">
                                    <textarea class="form-control" rows="3" name="description" placeholder="商品详情描述" >{{old('description')}}</textarea>
                                </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">商品图片</label>
                            <div class="col-sm-10">
                                <input  rows="3" type="file" name="cover" id="exampleInputFile">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">是否开放销售</label>
                            <div class="col-sm-10">
                               <input type="radio" name="is_onsale" value="1" checked="checked">是 
                               <input type="radio" name="is_onsale" value="0">否
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">是否能单独销售</label>
                            <div class="col-sm-10">
                               <input type="radio" name="is_alone_sale" value="1" checked="checked">是 
                               <input type="radio" name="is_alone_sale" value="0">否
                            </div>
                        </div>
                      

                        
                     
                    </div>
               
                </div>
              <!-- /.tab-pane -->

                <div class="tab-pane" id="settings">
                    <div class="box-body">
                        <div class="form-group " id="goods_type">
                            <label for="inputEmail3" class="col-sm-2 control-label">商品类型</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="category" name="cat_id">
                                    <option value="">商品类型</option>
                                    @foreach($category as $v)
                                    <option value="{{$v['id']}}">{{$v['name']}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>

                       

                        <div class="form-group">
                                <label for="inputEmail3" class="col-sm-2 control-label">sku</label>
                                <div class="col-sm-10">
                                    <table id="example2" class="table table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <th></th>
                                            <th>sku属性</th>
                                            <th>属性值</th>
                                            <th>价格</th>
                                            <th>数量</th>    
                                        </tr>
                                        </thead>
                                         <tbody id="tbody">
                                     


                    
                                        </tbody>
                                    </table> 
                                </div>
                        </div>

                    </div>
                </div>
                <div class="tab-pane" id="package">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">是否是套餐</label>
                            <div class="col-sm-10">
                               <input type="radio" name="is_alone_sale" value="1">是 
                               <input type="radio" name="is_alone_sale" value="0" checked="checked">否
                            </div>
                        </div>
                    </div>
                </div>
            
              <!-- /.tab-pane -->
                </div>
                <div class="box-footer">
                <button type="submit" class="btn btn-default" onClick="javascript:history.back()">返回</button>
                <button type="submit" class="btn btn-info pull-right ">提交</button>
              </div>
            </form>
            <!-- /.tab-content -->
            </div>
          <!-- /.nav-tabs-custom -->
    </div>
    <!-- /.content -->

    
    </section>

 


@endsection

@section('script')
    <script type="text/javascript">
        
        $(".tab-pane").on("change","#category",function(){
        	$(".choose_shux").remove()
        	$("#tbody").html('')
            var _this=$(this)
            if(_this.val()==""){
                return false;
            }
            var url="{{route('admin.item.getAttributeName')}}?cat_id="+_this.val();
            $.get(url, {}, function(data){
                    var data=data.data
                    var str="";
                    
                        str+='<div class="form-group choose_shux">'
                        str+= '<label for="inputEmail3" class="col-sm-2 control-label">选择属性</label>'
                        str+=  ' <div class="col-sm-10">'
                        for(var k in data){  
                            str+= '<input type="checkbox"  name="attr_id" value="'+data[k].id+'">'+data[k].name+''
                        }
                        str+='<button type="button" class="btn btn-info get-sku">获取属性组合</button>'
                        str+=    '</div>'
                        str+='</div>'
                    $("#goods_type").after(str);
                    
            })
        })

        $(".tab-pane").on("click",".get-sku",function(){
            var str=""
            $.each($('input[name="attr_id"]:checked'),function(i){
               
                    if(i==0){
                        str=$(this).val()
                    }else{
                        str=str+","+$(this).val()
                    }
                     
            });
            $("#tbody").html('')
            var url="{{route('admin.item.getAttribute')}}?attr_id="+str;
            $.get(url, {}, function(data){
                var tmp=data.data.tmp;
                var type=data.data.type;
                var sku=data.data.sku;
                var str=""
                var price=$("#price").val();
                var market_price=$("#market_price").val();
                for(var k in tmp){
                    
                    str+='<tr calss="tr">'
                    str+='<input name="skuidstr[]" type="hidden" value="'+sku[k]+'">'
                    str+='<input name="skunamestr[]" type="hidden" value="'+tmp[k]+'">'
                    str+='<td><input type="checkbox" ></td>'                 
                    str+='<td>'+type[k]+'</td>'
                    str+='<td>'+tmp[k]+'</td>'
                    str+='<td style="width: 20%"><input type="text" class="form-control" name="skuprice[]" value="'+price+'"></td>'
                    str+='<td style="width: 20%"><input type="text" class="form-control" name="skustock[]" value="100"></td>'
                    str+='</tr>'
                }
                
                $("#tbody").prepend(str);

            })
        })

    

    </script>
@endsection